<?php
/**
 * tpshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: IT宇宙人 2015-08-10 $
 */
namespace Home\Controller;
use Think\Page;
use Think\Verify;
class IndexController extends BaseController {

	public function index() {

		// 如果是手机跳转到 手机模块
		//		if (true == isMobile()) {
		//			header("Location: " . U('Mobile/Index/index'));
		//		}
		//		$driver = M('users') -> where("type=2") -> select();
		//		$route = M('publish') -> where("type=2 and is_recommend=1") -> order('createtime desc') -> select();
		//		$cartype = M('cartype') -> select();
		//		foreach ($route as $key => $value) {
		//
		//			$uid = $value['userid'];
		//
		//			$res = M('users') -> where("user_id = $uid") -> find();
		//			$route[$key]['head_pic'] = $res['head_pic'];
		//		}
		//		$comments = M('comments') -> order('createtime desc') -> limit('0,5') -> select();
		//
		//		$this -> assign('driver', $driver);
		//		$this -> assign('route', $route);
		//		$this -> assign('comments', $comments);
		//		$this -> assign('cartype', $cartype);
		//主题

		//目的地
		$desc_list = M('desc') -> select();

		foreach ($desc_list as $key => $value) {
			$desc_list[$key]['list'] = M('product') -> where("destination = '{$value['value']}'") ->cache(TRUE,SQL_CACHE_TIME)-> select();//可以 加数据库缓存
			foreach ($desc_list[$key]['list'] as $key1 => $value1) {

				$baseinfo = json_decode($value1['p_baseinfo'], TRUE);

				$desc_list[$key]['list'][$key1]['name'] = $baseinfo['name'];
				$desc_list[$key]['list'][$key1]['feature'] = $baseinfo['feature'];
				$desc_list[$key]['list'][$key1]['price'] = number_format($baseinfo['price']);
				$desc_list[$key]['list'][$key1]['logo'] = $baseinfo['logo'];
				$desc_list[$key]['list'][$key1]['startplace'] = $baseinfo['startplace'];
                $route_list['list'][]=$desc_list[$key]['list'][$key1];
			}

		}
		//主题
		
		$route_list['family_count'] = M('product') -> where('topic = "family"') -> count();
		$route_list['romantic_count'] = M('product') -> where('topic = "romantic"') -> count();
		$route_list['classic_count'] = M('product') -> where('topic = "classic"') -> count();
		$route_list['delicious_count'] = M('product') -> where('topic = "delicious"') -> count();
		$route_list['explore_count'] = M('product') -> where('topic = "explore"') -> count();

//			var_dump($route_list['list']);
//			exit;

		$scenery = M('article') -> where('cat_id = 55') -> limit('0,4') -> select();

		//		var_dump($cat_list);
		//		exit;
//		var_dump($route_list);
//		exit;
		$this -> assign('desc_list', $desc_list);
		$this -> assign('scenery', $scenery);
		$this -> assign('route_list', $route_list);
		$this -> display();
	}

	// 验证码
	public function verify() {
		//验证码类型
		$type = I('get.type') ? I('get.type') : '';
		$fontSize = I('get.fontSize') ? I('get.fontSize') : '40';
		$length = I('get.length') ? I('get.length') : '4';

		$config = array('fontSize' => $fontSize, 'length' => $length, 'useCurve' => true, 'useNoise' => false, );
		$Verify = new Verify($config);
		$Verify -> entry($type);
	}

}
